package com.star.langchain.learn.controller;

import java.util.ArrayList;
import java.util.List;

import dev.langchain4j.data.message.*;
import dev.langchain4j.store.memory.chat.ChatMemoryStore;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/memory")
public class MemoryController {

    @Autowired
    private ChatMemoryStore memoryStore;

    @PostMapping()
    public String insert(Long memoryId) {

        // when
        List<ChatMessage> chatMessages = new ArrayList<>();
        chatMessages.add(new SystemMessage("You are a large language model working with Langchain4j"));
        List<Content> userMsgContents = new ArrayList<>();
        userMsgContents.add(new ImageContent("someCatImageUrl"));
        chatMessages.add(new UserMessage("What do you see in this image?", userMsgContents));
        memoryStore.updateMessages(memoryId, chatMessages);
        return "success";
    }

    @DeleteMapping()
    public String delete(Long memoryId) {
        memoryStore.deleteMessages(memoryId);
        List<ChatMessage> messages = memoryStore.getMessages(memoryId);
        return "success";
    }

}
